package com.jy.rhin.facade.infra.controller.notification;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.infra.repo.notfication.participant.query.ParticipantQueryHandler;
import com.jy.rhin.sdk.dto.notification.EditPublisherDto;
import com.jy.rhin.sdk.dto.notification.PublisherDto;
import com.jy.rhin.sdk.dto.notification.PublisherShortDto;
import com.jy.rhin.sdk.dto.notification.req.PublisherOrSubscriberReqDto;
import com.jy.rhin.sdk.feign.client.PublisherFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dhl
 * @date 2022/6/28
 * @Description 发布管理api
 */
@RestController
@RequestMapping("/infra/notification/publisher")
@Api(tags = "事件总线api", value = "发布者管理api")
@Slf4j
public class PublisherController implements PublisherFeign {

    @Resource
    private ParticipantQueryHandler participantQueryHandler;
    @Resource
    private NotificationApplicationService notificationApplicationService;

    @Override
    @ApiOperation("发布者管理api-发布者分页查询")
    @GetMapping("/queryPublisherPage")
    public Result<Page<PublisherDto>> queryPublisherPage(PublisherOrSubscriberReqDto req) {
        return Result.success(participantQueryHandler.queryPublisherPage(req));
    }

    @Override
    @ApiOperation("发布者管理api-发布者列表查询")
    @GetMapping("/queryPublisherList")
    public Result<List<PublisherShortDto>> queryPublisherList() {
        return Result.success(participantQueryHandler.queryPublisherList());
    }

    @Override
    @ApiOperation("发布者管理api-发布者编辑")
    @PostMapping("/editPublisher")
    public Result<Long> editPublisher(@RequestBody EditPublisherDto dto) {
        return Result.success(notificationApplicationService.editPublisher(dto));
    }

}
